package per.zdb.watcher.utils;

import android.util.Log;
import android.widget.Toast;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;

import org.json.JSONObject;

import per.zdb.watcher.MainActivity;
import per.zdb.watcher.MyApplication;
import per.zdb.watcher.common.JsonRequestListener;

/**
 * Created by Adobe Chow  2017/9/24.
 * Copyright © 2017 周多兵. All Rights Reserved.
 */

public class HttpKit {

    public static void post(String url, JSONObject data, final JsonRequestListener jsonRequestListener){
        Log.i("zdb info","请求url:"+url);
        Log.i("zdb info","请求参数:"+data);

        final JsonObjectRequest request = new JsonObjectRequest( url, new Response.Listener<JSONObject>(){
            @Override
            public void onResponse(JSONObject response) {
                Log.i("zdb log","得到响应数据："+response);
                jsonRequestListener.onResponse(response);
            }
        }, new Response.ErrorListener(){

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("zdb log","错误："+error.getMessage(),error);
            }
        });
        MyApplication.getHttpQueues().add(request);
    }

}
